chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
	let cmd = request.cmd;
	switch (cmd) {
		case "not_login":
			setCookie("unescape", "获取账号信息失败，请先登陆！")
			break
		case "has_login":
			delCookie("unescape")
			break
		case "today_did":
			setCookie("succ", "已获取完成最大经验")
			delCookie("unescape")
			delCookie("error")
			break
		case "start_do":
			delCookie("succ")
			break
		case "did_unexcept":
			setCookie("unescape", "执行异常,请停用插件，防止硬币损失")
			break
		case "response_err":
			setCookie("error", "请求错误，请单击bilibili页面后按F12，打开开发者工具，将错误信息截图发送给开发者")
			break
		case "response_unexcept":
			setCookie("unescape", "请求异常，请稍后重试，一直失败请联系开发者")
			break
	}

	// sendResponse("popup返回值");
});

//写cookies 
function setCookie(name, value) {
	let Days = 30;
	let exp = new Date();
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies 
function getCookie(name) {
	let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

	if (arr = document.cookie.match(reg))

		return unescape(arr[2]);
	else
		return null;
}

//删除cookies 
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null)
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}